# _*_coding:utf-8_*_
__author__ = 'gerry'

products = [
    ['Iphone', 5800],
    ['Ipad', 4000],
    ['Testla', 800000],
    ['Coffee', 35],
    ['Clothes', 500],
    ['Shoes', 800]
]

salary = 9000
shop_list = []
shop_flag = True
quit = "quit"
all_price = []
total_money = 0.0

while shop_flag:
    for index, p in enumerate(products):
        print index + 1, '\t', p[0], '\t', p[1]
    print "if you want to settle accounts,please entry the \"q\""
    choice = raw_input("Choose sth to buy:").strip()
    if choice.isdigit():
        choice = int(choice) - 1
        p_price = products[choice][1]
        if p_price <= salary:
            shop_list.append(products[choice])
            all_price.append(p_price)
            salary = salary - p_price
            print "you has added the %s into your shopping basket,your current balance is %s $" % (
                products[choice][0], salary)
        else:
            print "your balance is not enough!"
    elif choice == 'q':
        print "-------------shopint list----------------------"
        for index, L in enumerate(shop_list):
            print index + 1, "\t", L[0], "\t", L[1]
        print "Total money:",
        for i in range(len(all_price)):
            total_money += all_price[i]
        print "Total money:%s"%total_money
        print "Looking forward to your next visit!"
        shop_flag = False
    else:
        print("your input is wrong! please input again!")
        continue
